<?php
error_reporting(E_WARNING);
include_once '../includes/metodos.php';
connectSql();
checkUser();

if(!empty($_POST['cmd']) && $_POST['cmd']== 'insert'){
	$query = mysql_query("INSERT INTO tb_agenda VALUES (NULL, ".$_POST['podo'].", NULL, '".$_POST['cliente']."', '".$_POST['data']."', '".$_POST['hora'].":00', 1, '".$_POST['tel']."', '".$_POST['cel']."')");
	if($query){
		echo '<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">location.href="index.php";</SCRIPT>';
	}else{
		die(mysql_error());
	}
}
?>
<head>
	<link rel="stylesheet" href="../js/jquery-ui-1.8.16.custom/development-bundle/themes/base/jquery.ui.all.css">
	<script src="../js/jquery-ui-1.8.16.custom/development-bundle/jquery-1.6.2.js"></script>
	<script src="../js/jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="../js/jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="../js/jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.datepicker.js"></script>
	<script src="../js/jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.autocomplete.js"></script>
	<script src="../js/jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.position.js"></script>
	<link rel="stylesheet" href="../js/jquery-ui-1.8.16.custom/development-bundle/demos/demos.css">
	
	<style type="text/css">
		.texto{
			font-family:arial;
			font-size: small;  
		}
	</style>
	
	<script>
	$(function() {
		var availableTags = [
			<?php 
				$query = mysql_query("SELECT * FROM tb_cliente");
				while ($row_cliente = mysql_fetch_array($query)){
					echo '"'.$row_cliente['nome'].' '.$row_cliente['sobrenome'].'",';
				}
			?>
		];
		$( "#tags" ).autocomplete({
			source: availableTags
		});
	});
	</script>
</head>



<form method="post" action="new.php">
	<label class="texto">Cliente:</label>
	<input type="text" name="cliente" id="tags"/><br/>
	<label class="texto">Telefone:</label>
	<input type="text" name="tel"/><br/>
	<label class="texto">Celular:</label>
	<input type="text" name="cel"/><br/>
	<input type="hidden" name="data" value="<?php echo $_POST['data'];?>"/>
	<input type="hidden" name="hora" value="<?php echo $_POST['hora'];?>"/>
	<input type="hidden" name="podo" value="<?php echo $_POST['podo'];?>"/>
	<input type="hidden" name="cmd" value="insert"/>
	<input type="submit" value="Salvar"/>
</form>